package com.pe1n.yangtaopai.presenter;

import android.util.Log;

import com.pe1n.yangtaopai.bean.ListBean;
import com.pe1n.yangtaopai.bean.ListfourBean;
import com.pe1n.yangtaopai.bean.ListthreeBean;
import com.pe1n.yangtaopai.bean.ListtwoBean;
import com.pe1n.yangtaopai.modle.ModleImpl;
import com.pe1n.yangtaopai.view.interfacese.IView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/11/22.
 */

public class PreaenterImpl implements IPresenter{
    private ModleImpl iModle;
    private IView iView;

    public PreaenterImpl(IView iView) {
        this.iModle = new ModleImpl();
        this.iView = iView;
    }
//1
    @Override
    public void LoadImageDate(String urlString) {
        iModle.getImageListBean(urlString)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ListBean>() {
                    @Override
                    public void onCompleted() {
                        //表示隐藏
                        iView.showProgress();

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ListBean listBean) {
                        iView.loadData(listBean);
                    }
                });
    }
//2
    @Override
    public void LoadImageTwoData(String urlString) {
        Log.e("tag","----------------get in");
        iModle.getImageListtwoBean(urlString)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ListtwoBean>() {
                    @Override
                    public void onCompleted() {
                        Log.e("tag","----------------onCompleted");
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("tag","----------------onError");

                    }

                    @Override
                    public void onNext(ListtwoBean listtwoBean) {
                        iView.LoadImageTwoData(listtwoBean);
                        Log.e("tag","----------------onNext");
                    }
                });
    }
//3
    @Override
    public void LoadImageThreeData(String urlString) {
        Log.e("tag","----------------get in3");
        iModle.getImageListthreeBean(urlString)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ListthreeBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ListthreeBean listthreeBean) {
                        iView.LoadImageThreeData(listthreeBean);

                    }
                });

    }
//4
    @Override
    public void LoadImageFourData(String urlString) {
        Log.e("tag","----------------get in4");
        iModle.getImageListfourBean(urlString)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ListfourBean>() {
                    @Override
                    public void onCompleted() {


                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(ListfourBean listfourBean) {
                        iView.LoadImageFourData(listfourBean);

                    }
                });

    }


}
